﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Indexers
{
    public class Matrix2x2
    {
        private double M11 { get; set; }
        private double M12 { get; set; }
        private double M21 { get; set; }
        private double M22 { get; set; }

        public double this[int i, int j]
        {
            get
            {
                if (i == 1 && j == 1) return M11;
                if (i == 1 && j == 2) return M12;
                if (i == 2 && j == 1) return M21;
                if (i == 2 && j == 2) return M22;

                throw new IndexOutOfRangeException("indexes should be 1 or 2");
            }
            set
            {
                if (i == 1 && j == 1)
                {
                    M11 = value;
                    return;
                }
                if (i == 1 && j == 2)
                {
                    M12 = value;
                    return;
                }
                if (i == 2 && j == 1)
                {
                    M21 = value;
                    return;
                }
                if (i == 2 && j == 2)
                {
                    M22 = value;
                    return;
                }
                
                throw new IndexOutOfRangeException("indexes should be 1 or 2");
            }
        }

        public override string ToString()
        {
            return string.Format("{0}\t{1}{2}{3}\t{4}", M11, M12, Environment.NewLine, M21, M22);
        }
    }
}
